﻿#include "CMakeSamRegZG.h"
#include <QMessageBox>
#include <QSettings>
#include "OraclDbThread.h"
#include "AccessDbThread.h"
#include "controldelegate.h"
#include "CManualSampleSys.h"
#include "Global.h"
#include "PublicGlobal.h"

CMakeSamRegZG::CMakeSamRegZG(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	m_pParent = NULL;
	m_pMakeSamRegModel = NULL;
	m_nCount = 0;
	m_nCurrent = -1;
	PreInit();
}

CMakeSamRegZG::~CMakeSamRegZG()
{
	if (nullptr != m_pMakeSamRegModel)
	{
		SAFE_DELETE(m_pMakeSamRegModel);
	}
	for (auto item : g_vecMakeSamRegItem) {
		delete item;
	}
	g_vecMakeSamRegItem.clear();
	m_pParent->m_pmakeSamRegZG = NULL;
}

void CMakeSamRegZG::PreInit()
{
	//初始化制样登记tableView
	ui.widget->ui.tableView->horizontalHeader()->setSectionsClickable(true);
	//设置表头字体
	//ui.widget->ui.tableView->horizontalHeader()->setFont(QFont("Microsoft YaHei UI", 15));
	if (!ui.widget->ui.tableView->alternatingRowColors())
	{
		ui.widget->ui.tableView->setAlternatingRowColors(true);
	}
	ui.widget->ui.tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
	ui.widget->ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
	ui.widget->ui.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
	ui.widget->ui.tableView->horizontalHeader()->setStretchLastSection(true);
	m_pMakeSamRegModel = new QStandardItemModel();
	m_pMakeSamRegModel->setColumnCount(21);
	m_pMakeSamRegModel->setHeaderData(0, Qt::Horizontal, "选择");//设置表头
	m_pMakeSamRegModel->setHeaderData(1, Qt::Horizontal, "序号");//设置表头
	m_pMakeSamRegModel->setHeaderData(2, Qt::Horizontal, "制样机编号");
	m_pMakeSamRegModel->setHeaderData(3, Qt::Horizontal, "编号");
	m_pMakeSamRegModel->setHeaderData(4, Qt::Horizontal, "采样编码");
	m_pMakeSamRegModel->setHeaderData(5, Qt::Horizontal, "制样编码");
	m_pMakeSamRegModel->setHeaderData(6, Qt::Horizontal, "3mm瓶底码");//设置表头
	m_pMakeSamRegModel->setHeaderData(7, Qt::Horizontal, "6mm瓶底码");//设置表头
	m_pMakeSamRegModel->setHeaderData(8, Qt::Horizontal, "6mm2瓶底码");//设置表头
	m_pMakeSamRegModel->setHeaderData(9, Qt::Horizontal, "0.2mm存查样瓶底码");
	m_pMakeSamRegModel->setHeaderData(10, Qt::Horizontal, "0.2mm分析样瓶底码");
	m_pMakeSamRegModel->setHeaderData(11, Qt::Horizontal, "3mm重量");//设置表头
	m_pMakeSamRegModel->setHeaderData(12, Qt::Horizontal, "6mm重量");//设置表头
	m_pMakeSamRegModel->setHeaderData(13, Qt::Horizontal, "6mm2重量");//设置表头
	m_pMakeSamRegModel->setHeaderData(14, Qt::Horizontal, "0.2mm存查样重量");
	m_pMakeSamRegModel->setHeaderData(15, Qt::Horizontal, "0.2mm分析样重量");
	m_pMakeSamRegModel->setHeaderData(16, Qt::Horizontal, "制样开始时间");//设置表头
	m_pMakeSamRegModel->setHeaderData(17, Qt::Horizontal, "制样结束时间");//设置表头
	m_pMakeSamRegModel->setHeaderData(18, Qt::Horizontal, "编辑模式");
	m_pMakeSamRegModel->setHeaderData(19, Qt::Horizontal, "操作员姓名");
	m_pMakeSamRegModel->setHeaderData(20, Qt::Horizontal, "样品总重量(KG)");
	ui.widget->ui.tableView->setModel(m_pMakeSamRegModel);

	ui.widget->ui.tableView->setColumnWidth(0, 45);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(1, 45);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(2, 105);
	ui.widget->ui.tableView->setColumnWidth(3, 50);
	ui.widget->ui.tableView->setColumnWidth(4, 200);
	ui.widget->ui.tableView->setColumnWidth(5, 200);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(6, 250);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(7, 250);
	ui.widget->ui.tableView->setColumnWidth(8, 250);
	ui.widget->ui.tableView->setColumnWidth(9, 250);
	ui.widget->ui.tableView->setColumnWidth(10, 250);
	ui.widget->ui.tableView->setColumnWidth(11, 135);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(12, 135);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(13, 135);
	ui.widget->ui.tableView->setColumnWidth(14, 250);
	ui.widget->ui.tableView->setColumnWidth(15, 250);
	ui.widget->ui.tableView->setColumnWidth(16, 250);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(17, 250);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(18, 250);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(19, 250);//设置列宽
	ui.widget->ui.tableView->setColumnWidth(20, 250);//设置列宽
	ui.widget->ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);//设置选中时为选中整行
	ui.widget->ui.tableView->setEditTriggers(QAbstractItemView::DoubleClicked);
	ui.widget->ui.tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
	if (!ui.widget->ui.tableView->alternatingRowColors())
	{
		ui.widget->ui.tableView->setAlternatingRowColors(true);
	}
	connect(m_pMakeSamRegModel, SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), this, SLOT(on_CurrentChanged(QModelIndex, QModelIndex, QVector<int>)));

	ui.SpecComboBox->addItem(QString("3mm"));
	ui.SpecComboBox->addItem(QString("6mm"));
	ui.SpecComboBox->addItem(QString("6mm2"));
	ui.SpecComboBox->addItem(QString("0.2mm存查样"));
	ui.SpecComboBox->addItem(QString("0.2mm分析样"));

	connect(ui.ChangeOkBtn, SIGNAL(clicked()), this, SLOT(on_ChangeOkBtn()));
	connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(on_AddAccessToTableView()));
	connect(ui.pushButtonWriteCode, SIGNAL(clicked()), this, SLOT(on_BottleCodeToChipBtn()));
	connect(ui.WeightOKBtn, SIGNAL(clicked()), this, SLOT(on_WeightOKBtn()));
	connect(ui.pushButtonCreateCode, SIGNAL(clicked()), this, SLOT(on_MakeBottleCodeBtn()));
	connect(ui.SubmitToOracleBtn, SIGNAL(clicked()), this, SLOT(on_SubmitToOracleBtn()));

	connect(ui.SpecComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(slot_ComBoBoxCurrentTextChanged(QString)));

	//初始化全选复选框
	ui.checkBox->setCheckState(Qt::CheckState::PartiallyChecked);
	ui.checkBox->setCheckState(Qt::CheckState::Unchecked);  //设置全选初始
	connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(slot_checkAll(int)));
	connect(ui.pushButtonDelete, SIGNAL(clicked()), this, SLOT(slot_PushbuttonDeleteClicked()));

	ui.label->setFont(QFont("Microsoft YaHei UI", 15));
	ui.pushButton_Readcode->hide();
	ui.lineEditBottomCodeRead->hide();
}

bool CMakeSamRegZG::CalcBottleCode(int nBottleType, char* szBottleCode, QString& strMSCode, QString strTime)
{
	unsigned char szData[56] = { 0 };
	QString strStartTime = "";
	//char strTime[56] = { 0 };
	char szStartTime[56] = { 0 };
	strMSCode = "";

	//得到时间前缀
	//得到当前选中行的制样编码
	int nRow = ui.widget->ui.tableView->currentIndex().row();
	QString strMakeSampleStartTime = strTime;
	ExtractDigit(strMakeSampleStartTime, szStartTime);
	strStartTime = QString(szStartTime);
	QString strStartTimeEx;
	strStartTimeEx = strStartTime.left(14);//取左边的14位
	strStartTimeEx.remove(0, 2);

	if (nBottleType == 0x01)  //3MM瓶底码
	{
		sprintf((char*)szData, "%s0331", strStartTimeEx.toLatin1().data());
	}
	if (nBottleType == 0x02)  //6MM瓶底码 1号瓶
	{
		sprintf((char*)szData, "%s0361", strStartTimeEx.toLatin1().data());
	}
	if (nBottleType == 0x03)  //6MM瓶底码 2号瓶
	{
		sprintf((char*)szData, "%s0362", strStartTimeEx.toLatin1().data());
	}
	if (nBottleType == 0x04)  //0.2MM清洗样1写码
	{
		sprintf((char*)szData, "%s0324", strStartTimeEx.toLatin1().data());
	}
	if (nBottleType == 0x05)  //0.2MM存查样写码
	{
		sprintf((char*)szData, "%s0322", strStartTimeEx.toLatin1().data());
	}
	if (nBottleType == 0x06)  //0.2MM分析样写码
	{
		sprintf((char*)szData, "%s0321", strStartTimeEx.toLatin1().data());
	}
	if (nBottleType == 0x07)  //0.2MM清洗样2写码
	{
		sprintf((char*)szData, "%s0323", strStartTimeEx.toLatin1().data());
	}

	sprintf(szBottleCode, (char*)szData);
	return true;
}

void CMakeSamRegZG::on_CurrentChanged(const QModelIndex &current, const QModelIndex &previous, const QVector<int> &roles)
{
	m_nCurrent = ui.widget->ui.tableView->currentIndex().row();
	//选择的单元格发生变化
	if (current.isValid())
	{
		//得到此行的所有字段内容
		QStandardItem* aItem = m_pMakeSamRegModel->itemFromIndex(current);
		QModelIndex Index = m_pMakeSamRegModel->index(current.row(), 5);
		QString strMakeSampleCode = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 6);
		QString str3MMCode = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 7);
		QString str6MM1Code = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 8);
		QString str6MM2Code = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 9);
		QString str2MM2Code = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 10);
		QString str2MM3Code = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 11);
		QString str3MMWeight = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 12);
		QString str6MM1Weight = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 13);
		QString str6MM2Weight = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 14);
		QString str2MM2Weight = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 15);
		QString str2MM3Weight = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 17);
		QString strEndTime = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 19);
		QString strOperName = m_pMakeSamRegModel->data(Index).toString();
		Index = m_pMakeSamRegModel->index(current.row(), 20);
		QString strSampleWeight = m_pMakeSamRegModel->data(Index).toString();

		if (current.column() == 6)//如果改变的是第6列,说明是3mm瓶底码进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strTHREEMMPUNTCODE, str3MMCode.toLatin1().data());
		}
		if (current.column() == 7)//如果改变的是7列,说明是6mm1瓶底码进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strSIXMMPUNTCODE1, str6MM1Code.toLatin1().data());
		}
		if (current.column() == 8)//如果改变的是第8列,说明是6mm2瓶底码进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strSIXMMPUNTCODE2, str6MM2Code.toLatin1().data());
		}
		if (current.column() == 9)//如果改变的是第9列,说明是0.2mm存查样瓶底码进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strTWOMMPUNTCODE2, str2MM2Code.toLatin1().data());
		}
		if (current.column() == 10)//如果改变的是第10列,说明是0.2mm分析样瓶底码进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strTWOMMPUNTCODE3, str2MM3Code.toLatin1().data());
		}
		if (current.column() == 11)//如果改变的是第11列,说明是3mm重量进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strTHREEMMPUNTWEIGHT, str3MMWeight.toLatin1().data());
		}
		if (current.column() == 12)//如果改变的是第12列,说明是6mm1重量进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strSIXMMPUNT1WEIGHT, str6MM1Weight.toLatin1().data());
		}
		if (current.column() == 13)//如果改变的是第12列,说明是6mm2重量进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strSIXMMPUNT2WEIGHT, str6MM2Weight.toLatin1().data());
		}
		if (current.column() == 14)//如果改变的是第14列,说明是0.2mm存查样重量进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strTWOMMPUNT2WEIGHT, str2MM2Weight.toLatin1().data());
		}
		if (current.column() == 15)//如果改变的是第15列,说明是0.2mm分析样重量进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strTWOMMPUNT3WEIGHT, str2MM3Weight.toLatin1().data());
		}
		if (current.column() == 17)//如果改变的是第17列,说明是制样结束时间进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strENDTIME, strEndTime.toLatin1().data());
		}
		if (current.column() == 19)//如果改变的是第19列,说明是操作员姓名进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strOPERATERNAME, strOperName.toLocal8Bit().data());
		}
		if (current.column() == 20)//如果改变的是第20列,说明是重量列进行了状态的改变
		{
			strcpy(g_vecMakeSamRegItem[current.row()]->strSampleWeight, strSampleWeight.toLatin1().data());
		}
		DbOperContent sDbOpeContent(enumSqlType::enMsReCode);
		if (NULL == sDbOpeContent.pMsReCodeTable)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
			return;
		}
		sDbOpeContent.pMsReCodeTable->nOpType = 22; //
		strcpy(sDbOpeContent.pMsReCodeTable->strMakeSampleCode, strMakeSampleCode.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strTHREEMMPUNTCODE, str3MMCode.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNTCODE1, str6MM1Code.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNTCODE2, str6MM2Code.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNTCODE2, str2MM2Code.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNTCODE3, str2MM3Code.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strTHREEMMPUNTWEIGHT, str3MMWeight.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNT1WEIGHT, str6MM1Weight.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNT2WEIGHT, str6MM2Weight.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNT2WEIGHT, str2MM2Weight.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNT3WEIGHT, str2MM3Weight.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strENDTIME, strEndTime.toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strOPERATERNAME, strOperName.toLocal8Bit());
		strcpy(sDbOpeContent.pMsReCodeTable->strSampleWeight, strSampleWeight.toLatin1());
		QString strErrMsg = "";
		QDStrs dsFields;
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return;
		}
	}
}

void CMakeSamRegZG::on_ChangeOkBtn()
{
	m_nCurrent = ui.widget->ui.tableView->currentIndex().row();
	//得到当前选中行的制样编码
	int nRow = ui.widget->ui.tableView->currentIndex().row();
	QModelIndex index = m_pMakeSamRegModel->index(nRow, 5);
	QString strMakeSampleCode = m_pMakeSamRegModel->data(index).toString();
	//将这个制样编码提取到编辑框
	ui.MakeSamCodeLineEdit->setText(strMakeSampleCode);
}

void CMakeSamRegZG::on_MakeBottleCodeBtn()
{
	if (m_nCurrent == -1)
	{
		QMessageBox::critical(NULL, "error", "请选择一列进行填入", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	ui.lineEditBottomCode->clear();
	char sz3mmBottleCode[56] = { 0 };
	char sz6mm1BottleCode[56] = { 0 };
	char sz6mm2BottleCode[56] = { 0 };
	char sz2mm2BottleCode[56] = { 0 };
	char sz2mm3BottleCode[56] = { 0 };
	QString strMSCode;
	//得到当前选中样品的时间
	m_nCurrent = ui.widget->ui.tableView->currentIndex().row();
	//得到当前选中行的制样编码
	int nRow = ui.widget->ui.tableView->currentIndex().row();
	QModelIndex index = m_pMakeSamRegModel->index(nRow, 16);
	QString strTime = m_pMakeSamRegModel->data(index).toString();

	//生成三种规格的编码
	if (ui.SpecComboBox->currentText() == "3mm")
	{
		if (false == CalcBottleCode(0x01, (char*)sz3mmBottleCode, strMSCode, strTime))
		{
			QMessageBox::critical(NULL, "error", "生成瓶底码失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}

		int nRow3MM = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index3MM = m_pMakeSamRegModel->index(nRow3MM, 6);
		m_pMakeSamRegModel->setData(index3MM, QString(sz3mmBottleCode));
		//将得到的瓶底码写入编辑框中
		ui.lineEditBottomCode->setText(sz3mmBottleCode);
	}
	else if(ui.SpecComboBox->currentText() == "6mm")
	{
		if (false == CalcBottleCode(0x02, (char*)sz6mm1BottleCode, strMSCode, strTime))
		{
			QMessageBox::critical(NULL, "error", "生成瓶底码失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}

		int nRow6MM1 = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index6MM1 = m_pMakeSamRegModel->index(nRow6MM1, 7);
		m_pMakeSamRegModel->setData(index6MM1, QString(sz6mm1BottleCode));
		//将得到的瓶底码写入编辑框中
		ui.lineEditBottomCode->setText(sz6mm1BottleCode);
	}
	else if (ui.SpecComboBox->currentText() == "6mm2")
	{
		if (false == CalcBottleCode(0x03, (char*)sz6mm2BottleCode, strMSCode, strTime))
		{
			QMessageBox::critical(NULL, "error", "生成瓶底码失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}

		int nRow6MM2 = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index6MM2 = m_pMakeSamRegModel->index(nRow6MM2, 8);
		m_pMakeSamRegModel->setData(index6MM2, QString(sz6mm2BottleCode));
		//将得到的瓶底码写入编辑框中
		ui.lineEditBottomCode->setText(sz6mm2BottleCode);
	}
	else if (ui.SpecComboBox->currentText() == "0.2mm存查样")
	{
		if (false == CalcBottleCode(0x05, (char*)sz2mm2BottleCode, strMSCode, strTime))
		{
			QMessageBox::critical(NULL, "error", "生成瓶底码失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}

		int nRow2MM2 = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index2MM2 = m_pMakeSamRegModel->index(nRow2MM2, 9);
		m_pMakeSamRegModel->setData(index2MM2, QString(sz2mm2BottleCode));
		//将得到的瓶底码写入编辑框中
		ui.lineEditBottomCode->setText(sz2mm2BottleCode);
	}
	else if (ui.SpecComboBox->currentText() == "0.2mm分析样")
	{
		if (false == CalcBottleCode(0x06, (char*)sz2mm3BottleCode, strMSCode, strTime))
		{
			QMessageBox::critical(NULL, "error", "生成瓶底码失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}

		int nRow2MM3 = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index2MM3 = m_pMakeSamRegModel->index(nRow2MM3, 10);
		m_pMakeSamRegModel->setData(index2MM3, QString(sz2mm3BottleCode));
		//将得到的瓶底码写入编辑框中
		ui.lineEditBottomCode->setText(sz2mm3BottleCode);
	}
}

void CMakeSamRegZG::on_BottleCodeToChipBtn()
{
	if (m_nCurrent == -1)
	{
		QMessageBox::information(NULL, "error", "请选择一行进行填入", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	if (ui.lineEditBottomCode->text() == "")
	{
		QMessageBox::information(NULL, "error", "请生成瓶底码", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}

	if (NULL == m_pParent->m_lpStartCodeDevice || NULL == m_pParent->m_lpStopCodeDevice || NULL == m_pParent->m_lpWriteCode || NULL == m_pParent->m_lpReadCode)
	{
		QMessageBox::critical(NULL, "error", "失败,驱动函数未加载", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	//先开启设备
	const char* szDeviceId = "";
	const char* szConfig = "";
	int ret = m_pParent->m_lpStartCodeDevice(szDeviceId, szConfig);
	if (ret == 0)
	{
		//写码
		std::string EditCode = ui.lineEditBottomCode->text().toStdString();
		unsigned char* a = const_cast<unsigned char*>((const unsigned char*)EditCode.c_str());
		ret = m_pParent->m_lpWriteCode(8, const_cast<unsigned char*>((const unsigned char*)EditCode.c_str()));
		if (0 == ret)
		{
			wchar_t strCode[33];
			//写码成功也需要关闭读写器
			ret = m_pParent->m_lpStopCodeDevice(NULL);
			if (0 != ret)
			{
				QMessageBox::critical(NULL, "error", "关闭写码器失败1", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
		}
		else
		{
			m_pParent->m_lpStopCodeDevice(NULL);
			QMessageBox::critical(NULL, "error", "写码失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}
	}
	else
	{
		QMessageBox::critical(NULL, "error", "连接读码器失败", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	QMessageBox::information(NULL, "", "写码成功", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
	return;
}

void CMakeSamRegZG::on_WeightOKBtn()
{
	if (m_nCurrent == -1)
	{
		QMessageBox::critical(NULL, "error", "请选择一行进行填入", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	QString strWeight = ui.WeightLineEdit->text();
	if (strWeight == "")
	{
		QMessageBox::critical(NULL, "error", "重量信息为空", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	if (ui.SpecComboBox->currentText() == "3mm")
	{
		int nRow = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index = m_pMakeSamRegModel->index(nRow, 11);

		m_pMakeSamRegModel->setData(index, strWeight);
	}
	else if (ui.SpecComboBox->currentText() == "6mm")
	{
		int nRow = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index = m_pMakeSamRegModel->index(nRow, 12);
		m_pMakeSamRegModel->setData(index, strWeight);
	}
	else if (ui.SpecComboBox->currentText() == "6mm2")
	{
		int nRow = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index = m_pMakeSamRegModel->index(nRow, 13);
		m_pMakeSamRegModel->setData(index, strWeight);
	}
	else if (ui.SpecComboBox->currentText() == "0.2mm存查样")
	{
		int nRow = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index = m_pMakeSamRegModel->index(nRow, 14);
		m_pMakeSamRegModel->setData(index, strWeight);
	}
	else if (ui.SpecComboBox->currentText() == "0.2mm分析样")
	{
		int nRow = ui.widget->ui.tableView->currentIndex().row();
		QModelIndex index = m_pMakeSamRegModel->index(nRow, 15);
		m_pMakeSamRegModel->setData(index, strWeight);
	}
	QMessageBox::information(NULL, "", "重量计入成功", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
	ui.WeightLineEdit->clear();
}

void CMakeSamRegZG::on_SubmitToOracleBtn()
{
	int nCount = 0;
	//首先检查是否没有勾选
	for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
	{
		if (true == g_vecMakeSamRegItem[i]->isChecked)
		{
			nCount++;
		}
	}
	if (0 == nCount)
	{
		QMessageBox::information(NULL, "", QString("请勾选需要提交的记录后再进行提交"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}
	//检查勾选住的记录时候将记录填写完整
	bool bFind = false;
	for (QVector<MakeSamRegItem*>::iterator it = g_vecMakeSamRegItem.begin(); it != g_vecMakeSamRegItem.end(); it++)
	{
		MakeSamRegItem* item = *it;
		if (item->isChecked == true)
		{
			if (strcmp(item->strEDITMODE, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			if (strcmp(item->strMakeSampleCode, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			if (strcmp(item->strMsDeviceID, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			if (strcmp(item->strSIXMMPUNT1WEIGHT, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			/*if (strcmp(item->strSIXMMPUNT2WEIGHT, "") == 0)
			{
			  QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			  return;
			}*/
			if (strcmp(item->strSIXMMPUNTCODE1, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			/*if (strcmp(item->strSIXMMPUNTCODE2, "") == 0)
			{
			  QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			  return;
			}*/
			if (strcmp(item->strTHREEMMPUNTCODE, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			if (strcmp(item->strTHREEMMPUNTWEIGHT, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			/*if (strcmp(item->strTWOMMPUNT2WEIGHT, "") == 0)
			{
			  QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			  return;
			}*/
			if (strcmp(item->strTWOMMPUNT3WEIGHT, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
			/*if (strcmp(item->strTWOMMPUNTCODE2, "") == 0)
			{
			  QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			  return;
			}*/
			if (strcmp(item->strTWOMMPUNTCODE3, "") == 0)
			{
				QMessageBox::information(NULL, "error", QString("制样码为%1的记录未填写完全,请填写完整").arg(item->strMakeSampleCode), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
				return;
			}
		}
	}
	//遍历全局的数组，找到勾选的记录
	for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
	{
		if (false == g_vecMakeSamRegItem[i]->isChecked)
		{
			continue;
		}
		//将新的制样记录插入到Oracle数据库中
		DbOperContent sDbOpeContent(enumSqlType::enMsReCode);
		if (NULL == sDbOpeContent.pMsReCodeTable)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
			return;
		}
		sDbOpeContent.pMsReCodeTable->nOpType = 1; //制样记录表中增加记录
		strcpy(sDbOpeContent.pMsReCodeTable->strMsDeviceID, g_vecMakeSamRegItem[i]->strMsDeviceID);
		strcpy(sDbOpeContent.pMsReCodeTable->strProviderNo, g_vecMakeSamRegItem[i]->strProviderNo);
		strcpy(sDbOpeContent.pMsReCodeTable->strMakeSampleCode, g_vecMakeSamRegItem[i]->strMakeSampleCode);
		strcpy(sDbOpeContent.pMsReCodeTable->strTHREEMMPUNTCODE, g_vecMakeSamRegItem[i]->strTHREEMMPUNTCODE);
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNTCODE1, g_vecMakeSamRegItem[i]->strSIXMMPUNTCODE1);
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNTCODE2, g_vecMakeSamRegItem[i]->strSIXMMPUNTCODE2);
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNTCODE2, g_vecMakeSamRegItem[i]->strTWOMMPUNTCODE2);
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNTCODE3, g_vecMakeSamRegItem[i]->strTWOMMPUNTCODE3);
		strcpy(sDbOpeContent.pMsReCodeTable->strTHREEMMPUNTWEIGHT, g_vecMakeSamRegItem[i]->strTHREEMMPUNTWEIGHT);
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNT1WEIGHT, g_vecMakeSamRegItem[i]->strSIXMMPUNT1WEIGHT);
		strcpy(sDbOpeContent.pMsReCodeTable->strSIXMMPUNT2WEIGHT, g_vecMakeSamRegItem[i]->strSIXMMPUNT2WEIGHT);
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNT2WEIGHT, g_vecMakeSamRegItem[i]->strTWOMMPUNT2WEIGHT);
		strcpy(sDbOpeContent.pMsReCodeTable->strTWOMMPUNT3WEIGHT, g_vecMakeSamRegItem[i]->strTWOMMPUNT3WEIGHT);
		strcpy(sDbOpeContent.pMsReCodeTable->strSTARTTIME, g_vecMakeSamRegItem[i]->strSTARTTIME);
		strcpy(sDbOpeContent.pMsReCodeTable->strENDTIME, QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toLatin1().data());
		strcpy(sDbOpeContent.pMsReCodeTable->strEDITMODE, "0");
		strcpy(sDbOpeContent.pMsReCodeTable->strOPERATERNAME, g_vecMakeSamRegItem[i]->strOPERATERNAME);
		strcpy(sDbOpeContent.pMsReCodeTable->strSampleWeight, g_vecMakeSamRegItem[i]->strSampleWeight);

		QString strErrMsg = "";
		QDStrs dsFields;
		if (g_nOracleorAccess == 0)
		{
			if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
				return;
			}
		}
		else
		{
			if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
				return;
			}

		}
		//更新本地的Access数据库中记录状态为已经提交
		DbOperContent sDbOpeContent2(enumSqlType::enMsReCode);
		if (NULL == sDbOpeContent2.pMsReCodeTable)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
			return;
		}
		sDbOpeContent2.pMsReCodeTable->nOpType = 2; //更新数据
		strcpy(sDbOpeContent2.pMsReCodeTable->strMakeSampleCode, g_vecMakeSamRegItem[i]->strMakeSampleCode);
		strcpy(sDbOpeContent2.pMsReCodeTable->strENDTIME, QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toLatin1().data());
		QString strErrMsg2 = "";
		QDStrs dsFields2;
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent2, &dsFields2, strErrMsg2))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return;
		}
		ADDMSG("系统信息", enEventInfo, FL, _Q(QString("制样码为%1的样品记录已提交到管控数据库").arg(g_vecMakeSamRegItem[i]->strMakeSampleCode)));
	}

	QMessageBox::information(NULL, "", QString("成功提交%1个记录").arg(nCount), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
	//将打勾的记录和列表中的记录删除
	int i = 0;
	for (auto it = g_vecMakeSamRegItem.begin(); it != g_vecMakeSamRegItem.end(); it++)
	{
		MakeSamRegItem* item = *it;
		if (item->isChecked == true)
		{
			m_pMakeSamRegModel->removeRow(i);//删除tableview中选中的行
			if (nullptr != *it)
			{
				SAFE_DELETE(g_vecMakeSamRegItem[i]);
			}
			g_vecMakeSamRegItem.erase(it);
			it--;//迭代器回退
			i--;
		}
		i++;
	}
	//最后将全选复选框设为未选中
	ui.checkBox->setCheckState(Qt::Unchecked);
	ui.MakeSamCodeLineEdit->clear();
}

void CMakeSamRegZG::on_AddAccessToTableView()
{
	//将本地未提交的记录更新到列表中
	DbOperContent sDbOpeContent(enumSqlType::enMsReCode);
	if (NULL == sDbOpeContent.pMsReCodeTable)
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
		return;
	}
	sDbOpeContent.pMsReCodeTable->nOpType = 21; //根据是否提交查询记录
	QString strErrMsg = "";
	QDStrs dsFields;
	if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
	{
		ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
		return;
	}
	if (dsFields.size() > 0)
	{
		for (int i = 0; i < dsFields.size(); i++)
		{
			QVector<QString> vecSampleRegTable = dsFields.at(i);
			if (vecSampleRegTable.size() < 39)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样登记表中的列数过少，第%d行数据无效")));
			}
			QString strMsdeviceId = vecSampleRegTable.at(2);
			QString strProviderNo = vecSampleRegTable.at(3);
			QString strMakeSampleCode = vecSampleRegTable.at(4);
			QString strTHREEMMPUNTCODE = vecSampleRegTable.at(6);
			QString strSIXMMPUNTCODE1 = vecSampleRegTable.at(9);
			QString strSIXMMPUNTCODE2 = vecSampleRegTable.at(12);
			QString strTWOMMPUNTCODE2 = vecSampleRegTable.at(18);
			QString strTWOMMPUNTCODE3 = vecSampleRegTable.at(20);
			QString strTHREEMMPUNTWEIGHT = vecSampleRegTable.at(25);
			QString strSIXMMPUNT1WEIGHT = vecSampleRegTable.at(26);
			QString strSIXMMPUNT2WEIGHT = vecSampleRegTable.at(27);
			QString strTWOMMPUNT2WEIGHT = vecSampleRegTable.at(29);
			QString strTWOMMPUNT3WEIGHT = vecSampleRegTable.at(30);
			QString strSTARTTIME = vecSampleRegTable.at(0);
			QString strENDTIME = vecSampleRegTable.at(33);
			QString strEDITMODE = vecSampleRegTable.at(34);
			QString strOPERATERNAME = vecSampleRegTable.at(35);
			QString strSampleWeight = vecSampleRegTable.at(36);
			QString strIsSubmit = vecSampleRegTable.at(37);
			int nRowCount = m_pMakeSamRegModel->rowCount();


			//遍历全局数组,将已经存在的制样记录屏蔽掉,只要历史未提交的数据
			bool bFind = false;
			for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
			{
				if (strcmp(g_vecMakeSamRegItem[i]->strMakeSampleCode, strMakeSampleCode.toLatin1().data()) == 0)
				{
					bFind = true;
					break;
				}
			}
			if (true == bFind)
			{
				continue;
			}
			//全局的数据中插入数据
			MakeSamRegItem* pItem = new MakeSamRegItem();
			pItem->isChecked = false;
			strcpy(pItem->strMsDeviceID, "260003");
			strcpy(pItem->strProviderNo, strProviderNo.toLatin1().data());
			strcpy(pItem->strMakeSampleCode, strMakeSampleCode.toLatin1().data());
			strcpy(pItem->strTHREEMMPUNTCODE, strTHREEMMPUNTCODE.toLatin1().data());
			strcpy(pItem->strSIXMMPUNTCODE1, strSIXMMPUNTCODE1.toLatin1().data());
			strcpy(pItem->strSIXMMPUNTCODE2, strSIXMMPUNTCODE2.toLatin1().data());
			strcpy(pItem->strTWOMMPUNTCODE2, strTWOMMPUNTCODE2.toLatin1().data());
			strcpy(pItem->strTWOMMPUNTCODE3, strTWOMMPUNTCODE3.toLatin1().data());
			strcpy(pItem->strTHREEMMPUNTWEIGHT, strTHREEMMPUNTWEIGHT.toLatin1().data());
			strcpy(pItem->strSIXMMPUNT1WEIGHT, strSIXMMPUNT1WEIGHT.toLatin1().data());
			strcpy(pItem->strSIXMMPUNT2WEIGHT, strSIXMMPUNT2WEIGHT.toLatin1().data());
			strcpy(pItem->strTWOMMPUNT2WEIGHT, strTWOMMPUNT2WEIGHT.toLatin1().data());
			strcpy(pItem->strTWOMMPUNT3WEIGHT, strTWOMMPUNT3WEIGHT.toLatin1().data());
			strcpy(pItem->strOPERATERNAME, strOPERATERNAME.toLocal8Bit().data());
			strcpy(pItem->strSTARTTIME, strSTARTTIME.toLatin1().data());
			strcpy(pItem->strEDITMODE, "0");
			strcpy(pItem->strSampleWeight, strSampleWeight.toLatin1().data());
			g_vecMakeSamRegItem.push_back(pItem);

			//关联采样编码
			//在Oracle数据库三级编码表中查找对应的采样编码
			DbOperContent sDbOpeContent(enumSqlType::enenThreeLevelCode);
			if (NULL == sDbOpeContent.pThreeLevelCodeTable)
			{
				ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表指针创建失败")));
				return;
			}
			sDbOpeContent.pThreeLevelCodeTable->nOpType = 3; //根据制样码关联采样码
			strcpy(sDbOpeContent.pThreeLevelCodeTable->szMakeSampleCode, strMakeSampleCode.toLatin1().data());
			QString strErrMsg = "";
			QDStrs dsFields;
			if (g_nOracleorAccess == 0)
			{
				if (false == g_pDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}
			}
			else
			{
				if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
					return;
				}

			}
			//开始解析三级编码表数据
			QString strSampleCode;//采样码

			if (dsFields.size() == 1)
			{
				QVector<QString> vecTHREELEVELCODEINFO = dsFields.at(0);
				if (vecTHREELEVELCODEINFO.size() < 17)
				{
					ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("三级编码表中的列数过少，第%d行数据无效")));
				}
				strSampleCode = vecTHREELEVELCODEINFO.at(3);
			}
			
			QList<QStandardItem*> item;
			item.append(new QStandardItem());//选择
			item.append(new QStandardItem(QString::number(m_nCount++)));//序号
			item.append(new QStandardItem("260003"));//制样机编号
			item.append(new QStandardItem(strProviderNo));//供应商编号
			item.append(new QStandardItem(strSampleCode));//采样编码
			item.append(new QStandardItem(strMakeSampleCode));//制样编码
			item.append(new QStandardItem(strTHREEMMPUNTCODE));//3mm瓶底码
			item.append(new QStandardItem(strSIXMMPUNTCODE1));//6mm1瓶底码
			item.append(new QStandardItem(strSIXMMPUNTCODE2));//6mm2瓶底码
			item.append(new QStandardItem(strTWOMMPUNTCODE2));//0.2mm存查样瓶底码
			item.append(new QStandardItem(strTWOMMPUNTCODE3));//0.2mm分析样瓶底码
			item.append(new QStandardItem(strTHREEMMPUNTWEIGHT));//3mm重量
			item.append(new QStandardItem(strSIXMMPUNT1WEIGHT));//6mm1重量
			item.append(new QStandardItem(strSIXMMPUNT2WEIGHT));//6mm2重量
			item.append(new QStandardItem(strTWOMMPUNT2WEIGHT));//0.2mm存查样重量码
			item.append(new QStandardItem(strTWOMMPUNT3WEIGHT));//0.2mm分析样重量码
			item.append(new QStandardItem(strSTARTTIME));//制样开始时间
			item.append(new QStandardItem());//制样结束时间
			item.append(new QStandardItem("人工制样"));//编辑模式
			item.append(new QStandardItem(strOPERATERNAME));//操作员姓名
			item.append(new QStandardItem(strSampleWeight));//样品总重量
			//设置居中显示
			for (int nRow = 0; nRow < item.count(); nRow++)
			{
				item.at(nRow)->setTextAlignment(Qt::AlignCenter);
			}
			m_pMakeSamRegModel->appendRow(item);
			//添加复选框
			QWidget *pwidget = new QWidget;
			QHBoxLayout *hlayout = new QHBoxLayout;
			hlayout->setAlignment(Qt::AlignLeft);
			QCheckBox *chebox = new QCheckBox;
			chebox->setObjectName("singleCheck");
			hlayout->addWidget(chebox);
			pwidget->setLayout(hlayout);
			connect(chebox, SIGNAL(clicked()), this, SLOT(slot_tCheckItem()));
			ui.widget->ui.tableView->setIndexWidget(m_pMakeSamRegModel->index(nRowCount, 0), pwidget);
		}
	}
}

void CMakeSamRegZG::on_CurrentTableViewChanged(const QModelIndex &newindex, const QModelIndex &oldindex)
{
	m_nCurrent = ui.widget->ui.tableView->currentIndex().row();
}

void CMakeSamRegZG::on_CheckBoxChanged(int state)
{
	if (state == Qt::Checked)//选中  全选
	{
		if (g_vecMakeSamRegItem.size() == 0)
		{
			QMessageBox::information(NULL, "", QString("列表中没有记录"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}
		for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
		{
			g_vecMakeSamRegItem[i]->isChecked = true;
		}
		QMessageBox::information(NULL, "", QString("全选成功"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		//遍历tableView，将所有的checkBox设置为选中
		/*for (int i = 0; i < m_pMakeSamRegModel->rowCount(); i++)
		{
		  int nRow = ui.widget->ui.tableView->currentIndex().row();
		  QModelIndex index = m_pMakeSamRegModel->index(nRow, 0);
		  QCheckBox* pWidget = new QCheckBox();
		  pWidget->setCheckable(true);
		  pWidget->setCheckState(Qt::Checked);
		  ui.widget->ui.tableView->setIndexWidget(index, pWidget);

		}*/
	}
	else if (state == Qt::Unchecked)//未选中  全部改为未选中
	{
		if (g_vecMakeSamRegItem.size() == 0)
		{
			QMessageBox::information(NULL, "", QString("列表中没有记录"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			return;
		}
		for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
		{
			g_vecMakeSamRegItem[i]->isChecked = false;
		}
		QMessageBox::information(NULL, "", QString("取消全选成功"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
	}
}

void CMakeSamRegZG::slot_checkAll(int status)
{
	int count = m_pMakeSamRegModel->rowCount();
	if (status == 2)
	{
		for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
		{
			g_vecMakeSamRegItem[i]->isChecked = true;
		}
	}
	else if (status == 0)
	{
		for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
		{
			g_vecMakeSamRegItem[i]->isChecked = false;
		}
	}
	for (int i = 0; i < count; i++)
	{
		QWidget *widget = ui.widget->ui.tableView->indexWidget(m_pMakeSamRegModel->index(i, 0));
		QCheckBox *check = widget->findChild<QCheckBox *>("singleCheck");
		switch (status) {
		case 0:
			check->setCheckState(Qt::CheckState::Unchecked);
			break;
		case 1:
			//check->setCheckState(Qt::CheckState::PartiallyChecked);
			break;
		case 2:
			check->setCheckState(Qt::CheckState::Checked);
			break;
		}
	}
}

void CMakeSamRegZG::slot_tCheckItem()
{
	int count = m_pMakeSamRegModel->rowCount();   //总行数
	QMap<int, int> rowMap;    //选中状态的map
	for (int i = 0; i < count; i++) {
		QWidget *widget = ui.widget->ui.tableView->indexWidget(m_pMakeSamRegModel->index(i, 0));
		QCheckBox *check = widget->findChild<QCheckBox *>("singleCheck");
		int status = check->checkState();    //按钮的状态
		switch (status) {
		case 0:
			rowMap.insert(i, 0);
			g_vecMakeSamRegItem[i]->isChecked = false;
			break;
		case 1:
			break;
		case 2:
			rowMap.insert(i, 1);    //如果是选中状态移除
			g_vecMakeSamRegItem[i]->isChecked = true;
			break;
		}
	}

	int tcount = 0;   //打沟的数量
	int fcount = 0;   //不打沟的数量
	QMapIterator<int, int> rowMapIterator(rowMap);
	rowMapIterator.toBack();
	while (rowMapIterator.hasPrevious())
	{
		int value;
		rowMapIterator.previous();
		value = rowMapIterator.value();
		if (value == 0) {
			fcount++;
		}
		else if (value == 1) {
			tcount++;
		}
	}

	//根据数量判断  全选状态
	if (tcount == count) {
		ui.checkBox->setCheckState(Qt::CheckState::Checked);
	}
	else if (fcount == count) {
		ui.checkBox->setCheckState(Qt::CheckState::Unchecked);
	}
	else {
		ui.checkBox->setCheckState(Qt::CheckState::PartiallyChecked);
	}
}

void CMakeSamRegZG::slot_ComBoBoxCurrentTextChanged(QString str)
{
	if (g_nProjectNo == 2 || g_nProjectNo == 5 || g_nProjectNo == 6)
	{
		if (ui.SpecComboBox->currentText() == "0.2mm分析样")
		{
			ui.label_7->setText("g");
		}
		else
		{
			ui.label_7->setText("kg");
		}
	}
	else if (g_nProjectNo == 3 || g_nProjectNo == 4)//岱海
	{
		if (ui.SpecComboBox->currentText() == "6mm")
		{
			ui.label_7->setText("kg");
		}
		else
		{
			ui.label_7->setText("g");
		}
	}
}

void CMakeSamRegZG::slot_PushbuttonDeleteClicked()
{
	int nCount = 0;
	//首先检查是否没有勾选
	for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
	{
		if (true == g_vecMakeSamRegItem[i]->isChecked)
		{
			nCount++;
		}
	}
	if (0 == nCount)
	{
		QMessageBox::information(NULL, "", QString("请勾选需要提交的记录后再进行删除"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		return;
	}

	int n = QMessageBox::information(NULL, "", QString("是否确定删除"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
	if (n == QMessageBox::No)
	{
		return;
	}

	//遍历全局的数组，找到勾选的记录
	for (int i = 0; i < g_vecMakeSamRegItem.size(); i++)
	{
		if (false == g_vecMakeSamRegItem[i]->isChecked)
		{
			continue;
		}

		DbOperContent sDbOpeContent(enumSqlType::enMsReCode);
		if (NULL == sDbOpeContent.pMsReCodeTable)
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(QString("制样记录表指针创建失败")));
			return;
		}

		sDbOpeContent.pMsReCodeTable->nOpType = 23; //根据是否提交查询记录
		strcpy(sDbOpeContent.pMsReCodeTable->strMakeSampleCode, g_vecMakeSamRegItem[i]->strMakeSampleCode);
		QString strErrMsg = "";
		QDStrs dsFields;
		if (false == g_pLocalDbThread->AddDbOperTask(&sDbOpeContent, &dsFields, strErrMsg))
		{
			ADDMSG("数据库模块", enEventAlarm, FL, _Q(strErrMsg));
			return;
		}

	}

	QMessageBox::information(NULL, "", QString("删除%1个记录").arg(nCount), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
	//将打勾的记录和列表中的记录删除
	int i = 0;
	for (auto it = g_vecMakeSamRegItem.begin(); it != g_vecMakeSamRegItem.end(); it++)
	{
		MakeSamRegItem* item = *it;
		if (item->isChecked == true)
		{
			m_pMakeSamRegModel->removeRow(i);//删除tableview中选中的行
			if (nullptr != *it)
			{
				SAFE_DELETE(g_vecMakeSamRegItem[i]);
			}
			g_vecMakeSamRegItem.erase(it);
			it--;//迭代器回退
			i--;
		}
		i++;
	}
	//最后将全选复选框设为未选中
	ui.checkBox->setCheckState(Qt::Unchecked);


}